package com.yang.String_;

public class LeetCode344 {
    public static void main(String[] args) {
        SolutionLeetCode344 solutionLeetCode344 = new SolutionLeetCode344();
        String s = "sdasdasfas";
        char[] chars = s.toCharArray();
        solutionLeetCode344.reverseString(chars);
        System.out.println(chars);
    }
}

class SolutionLeetCode344 {
    public void reverseString(char[] s) {
        int i = 0;
        int j = s.length-1;
        // 换位原理： a^=b 此时 a=a^b;  b^=a 此时b=a^b^b=a   a^b 此时a=a^b^a=b
        while (i < j){
            s[i] ^= s[j];
            s[j] ^= s[i];
            s[i] ^= s[j];
            i++;
            j--;
        }
    }
}
